package com.sample.thread.wait;

/**
 * @comments
 * @author zg
 * @date 2021年3月9日
 */
public class PhoneUser implements Runnable {

    private String name;

    private Phone phone;

    public PhoneUser(String name, Phone phone) {
        this.name = name;
        this.phone = phone;
    }

    @Override
    public void run() {
        synchronized (phone) {
            saySomething(name);
            try {
                phone.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(name+"：好的，这就挂电话。");
        }
    }
    
    private void saySomething(String userName) {
        
        System.out.println(userName + "通话中...");
    }

}
